import prompt from '@system.prompt';
import router from '@system.router';
export default {
    data:{

        num: 5,
        index:Math.floor(Math.random()*5),
        indexArray:[],
        goon:0,
        signal:0,
        count:0,
        againcountright:1,
        againcountwrong:1,
        text1: [ {
                     ques: "火灾中引起人员大量死亡的主要原因是（）",
                     cho:["被火直接烧死",
                     "烟气窒息致死",
                     "跳楼或惊吓致死"
                     ],
                     ans:1

                 },
                 {
                     ques: "使用灭火器扑救火灾时要对准火焰〔〕喷射",
                     cho:["上部",
                     "中部",
                     "根部"
                     ],
                     ans:2
                 },
                 {
                     ques: "当翻开房门闻到燃气气味时，首先应迅速〔〕，以防止引起火灾",

                     cho:["翻开燃气灶具查找漏气部位",
                     "翻开门窗通风",
                     "拨打 119向消防队报警"

                     ],
                     ans:1
                 },
                 {
                     ques: "检查燃气用具是否漏气时，通常采用〔〕来寻找漏气点",
                     cho:["划火柴",
                     "涂抹肥皂水",
                     "闻气味"
                     ],
                     ans:1
                 },
                 {
                     ques: "用灭火器灭火的最正确位置是〔 〕",
                     cho:["下风位置",
                     "上风或侧风位置 ",
                     "离起火点 10 米以上的位置"
                     ],
                     ans:1
                 },

        ],
//        题目乱序及选项乱序
        rand:function(){
            this.againcountright=1;
            this.againcountwrong=1;
            while(this.goon==0){
                this.signal=0;
                var chu=Math.floor(Math.random()*5);
                for (var i=0; i<this.indexArray.length; i++)
                {
                    if(chu==this.indexArray[i]){
                        this.signal=1;
                        break;
                    }
                }
                if(this.signal==0){
                    this.index=chu;
                    this.indexArray.push(chu);
                    this.goon=1;
                }
            }
        },
//        响应回答正确
        select_respondY:function(){
            console.log("Yes");
            if(this.againcountright==1){
                this.$app.$def.globalData.rightNum=this.$app.$def.globalData.rightNum+1;
            }
            prompt.showToast({
                message: '回答正确',
                duration: 1000,
            });
            this.count=this.count+1;
            if(this.count==1){
                this.indexArray.push(this.index);
            }

            if(this.indexArray.length<5){
                this.goon=0;
                this.rand();
            }else{
                prompt.showToast({
                    message: '恭喜！已完成本轮任务',
                    duration: 2000,
                    bottom:50
                });
                setTimeout(()=>{
                    router.push({
                        uri:'pages/questiontype/endtest/endtest',
                    })
                },2000);
            }
        },
//        响应回答错误
        select_respondN:function(){
            console.log("No");
            this.againcountright=0;
            if(this.againcountwrong==1){
                this.$app.$def.globalData.wrongNum=this.$app.$def.globalData.wrongNum+1;
            }
            this.againcountwrong=0;
            prompt.showDialog({
                title: '提示信息',
                message: '回答错误',
                buttons: [
                    {
                        text: '再想想',
                        color: '#666666',
                    },
                    {
                        text: '退出做题',
                        color: '#666666',
                    },
                ],
                success: function(data) {
                    //                     console.log('dialog success callback，click button : ' + data.index);
                    if(data.index==1){
                        router.push({
                            uri:'pages/questiontype/endtest/endtest'
                        })
                    }

                },
                cancel: function() {
                    console.log('dialog cancel callback');
                },
            });
        }


    },
//    答题结束
    select_over(){

        router.push({
            uri:'pages/questiontype/endtest/endtest'
        })


    },
    select1(){
        if(this.text1[this.index].ans==0){
            this.select_respondY();
        }else{
            this.select_respondN();
        }
    },
    select2(){
        if(this.text1[this.index].ans==1){
            this.select_respondY();
        }else{
            this.select_respondN();
        }
    },
    select3(){
        if(this.text1[this.index].ans==2){
            this.select_respondY();
        }else {
            this.select_respondN();
        }
    },
    select4(){
        if(this.text1[this.index].ans==3){
            this.select_respondY();
        }else {
            this.select_respondN();
        }
    },
}
